<?php
/**
 * --------------------------------------------------------------------
 * MCore精简框架
 * 作者：阿枫，QQ：52037872，Email：support@mdeve.com
 * --------------------------------------------------------------------
 *
 * SVN revision information:
 * @version $Revision: 1 $:
 * @author  $Author: zy $:
 * @date      $Date: 2017-03-10 21:12:21 +0800 (星期五, 10 三月 2017) $:
 */

class _OptionsClass extends __basic_def {

    function fetch($options_name, $options_default, $category="", $type="user") {
        global $_M;

        if(!is_object($_M->db)) $_M->db();
        $row = $_M->db->get_row(array("table"=>"options", "field"=>"options_value", "where"=>"type='{$type}' and options_name='{$options_name}'"));
        if(false === $row) {
            return $options_default;
        } else {
            return $row["options_value"];
        }
    }

    function store($options_name, $options_value, $category="", $type="user"){
        global $_M;

        $row = $_M->db->get_row(array("table"=>"options", "where"=>"type='{$type}' and options_name='{$options_name}' and category='{$category}'"));
        if(false === $row) return false;

        $data = array(
            "options_value" => $options_value,
        );
        $_M->db->update($data, array("table"=>"options", "where"=>"id={$row["id"]}"));
        return true;
    }

}